package ru.zombator.taskman.client.ui.images;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

/**
 * Реестр изображений, используемых клиентским приложением.
 * 
 * @author nvamelichev
 *
 */
public class Registry implements ImageNames {
    private static boolean isInitialized = false;
    private static ImageRegistry registry;
    
    private Registry() {
        // non-creatable
    }
    
    public static void init() {
        Display display = Display.getDefault();
        if (display != null) {
            registry = new ImageRegistry(display);
            
            Class<?> someClass = ImageNames.class;
            registry.put(CREATE_PROJECT, ImageDescriptor.createFromURL(
                    someClass.getResource("/icons/newProjectWiz.gif")));
            
            isInitialized = true;
        }
    }
    
    public static Image getImage(String key) {
        if (isInitialized)
            return registry.get(key);
        else
            return null;
    }
}
